<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>个人中心</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/css.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.picker.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.poppicker.css"/>
</head>

<body>
<style>
    [v-cloak] {
        display: none;
    }
</style>
<div id="app" v-cloak>
    <div class="my_userbody">
        <div class="my_user">
            <!--标题-->
            <div class="my_title"><h3>用户中心</h3></div>
            <!--头部-->
            <div class="my_userinfo">
                <div class="my_userinfol">
                    <img class="uservar" @click="changeAvatar" :src="avatar| filtersImg" alt="">
                    <div class="my_userinfolt" @click="goBasicdata">
                        <div class="my_userinfolt1">
                            <span>{{nickname}}</span>
<!--                            <img src="../image/iconvip.png" alt="">-->
                        </div>
                        <div class="my_userinfolt2">
                            <!--                            信誉值：{{score}}-->
                        </div>
                    </div>
                </div>
                <div class="my_userinfor" @click="goBasicdata">
                    <i class="icon iconfont icon-right"></i>
                </div>
            </div>
            <!--    公告-->
<!--            <div class="my_gonggao" v-if="ispay==1">-->
<!--                <div class="my_gonggaoitem bor-r-f" @click="goMessage">-->
<!--                    <img src="../image/my_icon2.png" alt="">-->
<!--                    <span>公告管理</span>-->
<!--                </div>-->
<!--                <div class="my_gonggaoitem" @click="goCharge">-->
<!--                    <img src="../image/my_icon1.png" alt="">-->
<!--                    <span>会员充值</span>-->
<!--                </div>-->
<!--            </div>-->
            <!--        操作-->
            <div class="caozuolist s-mt20">
<!--                <div class="caozuolist_item">-->
<!--                    <div class="caozuolist_iteml">-->
<!--                        <img class="myicon3" src="../image/my_icon3.png" alt="">-->
<!--                        <span>会员有效期</span>-->
<!--                    </div>-->
<!--                    <div class="caozuolist_itemr">-->
<!--                        <span>{{expiretime|getgroup}}</span>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="caozuolist_item" @click="gobio">
                    <div class="caozuolist_iteml">
                        <img class="myicon4" src="../image/my_icon4.png" alt="">
                        <span>自我介绍</span>
                    </div>
                    <div class="caozuolist_itemr">
                        <i class="icon iconfont icon-right"></i>
                    </div>
                </div>
                <div class="caozuolist_item" @click="getzixun">
                    <div class="caozuolist_iteml">
                        <img class="myicon5" src="../image/my_icon5.png" alt="">
                        <span>在线客服</span>
                    </div>
                    <div class="caozuolist_itemr">
                        <i class="icon iconfont icon-right"></i>
                    </div>
                </div>
                <div class="caozuolist_item" @click="getjuli">
                    <div class="caozuolist_iteml">
                        <img class="myicon6" src="../image/my_icon6.png" alt="">
                        <span>距离范围</span>
                    </div>
                    <div class="caozuolist_itemr">
                        <!--                        <span>{{distance:distancelist[0].value}}</span>-->
                        <span>{{distance}}KM</span><i class="icon iconfont icon-right"></i>
                    </div>
                </div>
            </div>
            <!--        登出-->
            <div class="my_logout" @click="logout">
                退出登录
            </div>
        </div>
    </div>
</div>
</body>

</html>
<script src="../script/mui.min.js"></script>
<script src="../script/mui.picker.js"></script>
<script src="../script/mui.poppicker.js"></script>
<script src="../aui/js/aui.js"></script>
<script src="../script/vue2.js"></script>
<script src="../script/vue-resource.min.js"></script>
<script src="../script/common.js"></script>
<script src="../script/city.data-3.js" type="text/javascript" charset="utf-8"></script>
<script>
    function openframe() {
        api.openFrame({
            name: 'address',
            url: 'widget://html/address.html',
            rect: {
                x: 0,
                y: 0,
                w: api.winWidth,
                h: api.winHeight
            },
            bgColor: 'rgba(0,0,0,0.6)',
            pageParam: {
                name: 'test'
            }
        });
    }

    // var mq;
    //
    // function initMeiQia() {
    //     //创建美洽
    //     mq = api.require('meiQia');
    //     //配置初始化美洽需要的appkey
    //     var param = {
    //         appkey: "e2c5d30914366f50937a34e805cf29be"                                  // 这里需要填写自己在美洽申请的appkey
    //     };
    //     var titleBarColor = {
    //         color: "#6638f0"
    //     };
    //     mq.setTitleBarColor(titleBarColor);
    //     var titleColor = {
    //         color: "#ffffff"
    //     };
    //     mq.setTitleColor(titleColor);
    //     //初始化美洽
    //     mq.initMeiQia(param, function (ret, err) {
    //         if (ret) {
    //             //初始化成功
    //             // alert(JSON.stringify(ret));
    //             meiQia_show()
    //         } else {
    //             //初始化失败
    //             alert(JSON.stringify(err));
    //         }
    //     })
    // };
    //
    // function meiQia_show() {
    //     mq.show();
    // }

    apiready = function () {
        function lt(id, xm, tx) {
            api
            api.openWin({
                reload: true,
                name: 'chat',
                url: 'widget://html/win_chat.html',
                pageParam: {
                    id: id,
                    zh: xm,
                    tx: tx
                },
                vScrollBarEnabled: false,
            });
            if ($api.getStorage('id') == id) {
            } else {
                var rong = api.require('rongCloud2');
                rong.clearMessagesUnreadStatus({
                    conversationType: 'PRIVATE',
                    targetId: id
                }, function (ret, err) {
                })
            }
            api.sendEvent({
                name: 'hhxx'
            });
        }

        api.addEventListener({
            name: 'address'
        }, function (ret, err) {
            // alert(ret.value.address)
            vm.address = ret.value.address
            vm.updateAddress(vm.address, ret.value.addid)
        });

        api.addEventListener({
            name: 'charge'
        }, function (ret, err) {
            // alert('ceshi')
            vm.getrefUserinfo()
        });
        var vm = new Vue({
            el: "#app",
            data: {
                userinfo: [],
                editAddress: false,
                userinfo2: [],
                bio: '',
                sfz: '',
                card: '',
                avatar: '',
                mobile: '',
                checked: 0,
                release: false,
                dingdan: [],
                address: '',
                appVersion: '1.0.0',
                money: 0,
                level: '普通会员',
                isyuehui: false,
                nickname: '',
                group: '',
                score: '',
                distances: '',
                distance: '',
                kefuid: '',
                kefuname: '',
                kefuimg: '',
                expiretime: '',
                ispay:0

            },
            mounted: function () {
                var that = this;
                if (!$api.getStorage('userInfo')) { //判断是否登录
                    if (api.systemType == "ios") {
                        var times = 0;
                    } else {
                        var times = 300;
                    }
                    api.openWin({ //未登录打开登陆窗口
                        name: 'login',
                        url: '../../html/login/login.html',
                        delay: times,
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                    return
                }
                that.appVersion = api.appVersion;
                that.getrefUserinfo()
                that.getdistance()
                that.getkefumessage()
                that.ispays()
            },
            methods: {
                getjuli: function () {
                    var that = this;
                    var picker = new mui.PopPicker();
                    picker.setData(that.distancelist)
//picker.pickers[0].setSelectedIndex(4, 2000);
                    picker.pickers[0].setSelectedValue('1', 2000);
                    picker.show(function (SelectedItem) {
                        that.postdistance(SelectedItem[0].value)
                    })
                },
                getMoney: function () {

                },
                getzixun: function () {
                    lt(this.kefuid, this.kefuname, this.kefuimg)
                },
                goBasicdata: function () {
                    api.openWin({
                        name: 'reg',
                        url: 'widget://html/my/basicdata.html',
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                gokefu: function () {
                    initMeiQia()
                },
                gobio: function () {
                    api.openWin({
                        name: 'reg',
                        url: 'widget://html/my/introduce.html',
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                tixian: function () {
                    api.openWin({
                        name: 'tixian',
                        url: 'widget://html/Cashwithdrawal/index.html',
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                goMessage: function () {
                    api.openWin({
                        name: 'message',
                        url: 'widget://html/message/list.html',
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                goShare: function () {
                    api.openWin({
                        name: 'reg',
                        url: 'widget://html/share/share.html',
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                // 约会开关
                yuehuiis: function () {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    console.log(token);
                    api.ajax({
                        url: ajaxRoute.onlocation,
                        method: 'post',
                        data: {
                            values: {
                                token: token,
                                is_location: !that.isyuehui ? 1 : 0,
                            }
                        }
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            that.isyuehui = !that.isyuehui
                            api.toast({msg: ret.msg, location: 'middle'});
                        } else {
                            api.hideProgress();
                            api.toast({msg: ret.msg, location: 'middle'});
                        }
                    });
                },
                ispays: function () {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    console.log(token);
                    api.ajax({
                        url: ajaxRoute.userispay,
                        method: 'post',
                        data: {
                            values: {
                                token: token
                            }
                        }
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            that.ispay = ret.data
                        } else {
                            api.hideProgress();
                        }
                    });
                },
                // 获取客服信息
                getkefumessage: function () {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    console.log(token);
                    api.ajax({
                        url: ajaxRoute.getcustom,
                        method: 'post',
                        data: {
                            values: {
                                token: token,
                            }
                        }
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            that.kefuid = ret.data.id
                            that.kefuname = ret.data.nickname
                            that.kefuimg = '../image/headimg.png'
                            // api.toast({msg: ret.msg, location: 'middle'});
                        } else {
                            api.hideProgress();
                            api.toast({msg: ret.msg, location: 'middle'});
                        }
                    });
                },
                // 获取距离数值
                getdistance: function () {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    console.log(token);
                    api.ajax({
                        url: ajaxRoute.distance,
                        method: 'post',
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            var list = ret.data
                            var list2 = []
                            console.log(JSON.stringify(list));
                            for (var i = 0; i < list.length; i++) {
                                var sss = {}
                                sss.value = list[i]
                                sss.text = list[i] + 'KM'
                                list2.push(sss)
                            }
                            that.distancelist = list2
                            console.log(JSON.stringify(list2));
                        } else {
                            api.hideProgress();
                            api.toast({msg: ret.msg, location: 'middle'});
                        }
                    });
                },
                // 提交距离
                postdistance: function (e) {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    console.log(token);
                    api.ajax({
                        url: ajaxRoute.userdistance,
                        method: 'post',
                        data: {
                            values: {
                                token: token,
                                distance: e
                            }
                        }
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            that.distance = e
                            api.toast({msg: ret.msg, location: 'middle'});
                        } else {
                            api.hideProgress();
                            api.toast({msg: ret.msg, location: 'middle'});
                        }
                    });
                },
                goMessage: function () {
                    api.openWin({ //未登录打开登陆窗口
                        name: 'charge',
                        url: 'widget://html/message/list.html',
                        delay: 0,
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                goCharge: function () {
                    api.openWin({ //未登录打开登陆窗口
                        name: 'charge',
                        url: 'widget://html/my/charge.html',
                        delay: 0,
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                goCashwithdrawal: function () {
                    api.openWin({ //未登录打开登陆窗口
                        name: 'charge',
                        url: 'widget://html/Cashwithdrawal/index.html',
                        delay: 0,
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                onRead: function (file) {
                    var that = this;
                    showProgress();
                    var token = $api.getStorage('userInfo').token
                    api.ajax({
                        url: ajaxRoute.avatarUpload,
                        method: 'post',
                        data: {
                            values: {
                                token: token,
                                imgData: file
                            }
                        }
                    }, function (res, err) {
                        api.hideProgress();
                        if (res.code == 1) {
                            api.toast({msg: '头像更换成功', location: 'middle'});
                            that.getrefUserinfo()
                        } else {
                            api.hideProgress();
                            api.toast({msg: res.msg, location: 'middle'});
                        }
                    })
                },
                goOrder: function (e) {
                    openWinto('order', 'procurement/order', e)
                },
                logout: function () {
                    var that = this;
                    $api.rmStorage('userInfo')
                    $api.rmStorage('token')
                    that.toLogin();
                    // showProgress();
                    // var token = $api.getStorage('userInfo').token
                    // api.ajax({
                    //     url: ajaxRoute.logout,
                    //     method: 'post',
                    //     data: {
                    //         values: {
                    //             token: token
                    //         }
                    //     }
                    // }, function (ret, err) {
                    //     api.hideProgress();
                    //
                    // });
                },
                changeAvatar: function () {
                    var that = this;
                    api.getPicture({
                        sourceType: 'library',
                        encodingType: 'jpg',
                        mediaValue: 'pic',
                        destinationType: 'base64',
                        quality: 50,
                        targetWidth: 750,
                        targetHeight: 750
                    }, function (ret, err) {
                        if (ret) {
                            var url = ret.data;
                            if (url == "") {
                                return;
                            }
                            // alert(JSON.stringify(ret))
                            that.onRead(ret.base64Data)
                        } else {
                            // alert(JSON.stringify(err));
                        }
                    });
                },
                toLogin: function () {
                    console.log('logins')
                    if (api.systemType == "ios") {
                        var times = 0;
                    } else {
                        var times = 300;
                    }
                    api.openWin({ //未登录打开登陆窗口
                        name: 'login',
                        url: 'widget://html/login/login.html',
                        delay: 0,
                        slidBackType: 'edge',
                        vScrollBarEnabled: false,
                        slidBackEnabled: false,
                    })
                },
                getEditAddress: function () {
                    var that = this;
                    var _getParam = function (obj, param) {
                        return obj[param] || '';
                    };
                    var picker = new mui.PopPicker({
                        layer: 3
                    });
                    picker.setData(cityData3);
                    picker.show(function (items) {
                        str = _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text');
                        that.updateAddress(str)
                    });
                },
                getUserInfo: function () {
                    this.userinfo = JSON.parse($api.getStorage('userinfo'))
                },
                cancelEditAddress: function () {
                    this.editAddress = false
                },
                confirmEditAddress: function (e) {
                    var address = e
                    var str = ''
                    for (var i = 0; i < address.length; i++) {
                        str += address[i].name + ' '
                    }
                    str = (str.substring(str.length - 1) == ' ') ? str.substring(0, str.length - 1) : str;
                    this.updateAddress(str)
                },
                updateAddress: function (e, id) {
                    var that = this;
                    var token = $api.getStorage('userInfo').token
                    api.ajax({
                        url: ajaxRoute.address,
                        method: 'post',
                        data: {
                            values: {
                                token: token,
                                address: e,
                                block: id
                            }
                        }
                    }, function (ret, err) {
                        if (ret.code == 1) {
                            api.hideProgress();
                            that.bio = e
                            api.toast({msg: '更新成功', location: 'middle'});
                            that.getrefUserinfo();
                        } else {
                            api.hideProgress();
                            api.toast({msg: ret.msg, location: 'middle'});
                        }
                    });
                },
                getrefUserinfo: function () {
                    var that = this;
                    showProgress();
                    var token = $api.getStorage('userInfo').token
                    api.ajax({
                        url: ajaxRoute.center,
                        method: 'post',
                        data: {
                            values: {
                                token: token
                            }
                        }
                    }, function (res, err) {
                        if (res.code == 1) {
                            api.hideProgress();
                            console.log("获取会员信息");
                            console.log(JSON.stringify(res))
                            that.dingdan = res.data
                            that.distance = res.data.distance
                            that.nickname = res.data.userinfo.nickname
                            that.avatar = res.data.userinfo.avatar
                            that.isyuehui = res.data.onlocation
                            that.money = res.data.money
                            that.group = res.data.group
                            that.score = res.data.score
                            that.expiretime = res.data.expiretime
                            console.log(that.avatar, 'ceshi')
                            that.$nextTick(function () {
                                cacheDataImg2()
                            })
                        } else {
                            api.hideProgress();
                            $api.rmStorage('userInfo')
                            $api.rmStorage('token')
                            that.toLogin();
                            api.toast({msg: res.msg, location: 'middle'});
                        }
                    });
                },
                //下拉刷新
                onRefresh: function () {
                    setTimeout(function () {
                        api.refreshHeaderLoadDone()
                        window.location.reload();
                    }, 1000);
                },
            },
            filters: {
                getTel: function (value) {
                    var phone = value
                    return phone.substr(0, 3) + "****" + phone.substr(7)
                },
                getCard: function (value) {
                    var phone = value
                    return phone.substr(0, 5) + "********" + phone.substr(12)
                },
                getchecked: function (e) {
                    var checked = ''
                    if (e == 0) {
                        checked = '审核中'
                    } else {
                        checked = '已审核'
                    }
                    return checked
                },
                filtersImg: function (img) {
                    console.log("00000000000000000");
                    console.log(img);
                    if (img == '') {
                        return '../image/headimg.png'
                    } else if (img.search("base64") != -1) {
                        return img
                    } else {
                        var imgs = ajaxUrl + '/' + img
                        return imgs;
                    }
                }, getgroup: function (e) {
                    var checked = ''
                    if (e == 0) {
                        checked = '永久'
                    } else {
                        checked = e
                    }
                    return checked
                }
            }
        })
    }
</script>
